
cc.Class({
    extends: cc.Component,

    properties: {
        className:"soundlayer",
        soundtoggle:{
            default:null,
            type:cc.Component,
        },
        musictoggle:{
            default:null,
            type:cc.Component,
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function () {
        this.node.thisJS = this; 
    },

    updateState:function(){
        if(global.Audio.getMusicState()==1){
            this.musictoggle.isChecked = false ;
        }else{
            this.musictoggle.isChecked = true ;
        }
        if(global.Audio.getSoundState()==1){
            this.soundtoggle.isChecked = false ;
        }else{
            this.soundtoggle.isChecked = true ;
        }
    },

    confirm:function(){
        var self = this ;
        console.log("confirm--->");
        console.log("this.musicState--->"+this.musicState);
        console.log("this.soundState--->"+this.soundState);
        global.Audio.updateMusicState(this.musicState)
        global.Audio.updateSoundState(this.soundState)
        this.scheduleOnce(function(){
            self.node.active = false ;
        },0.1)       
    },
    
    exit:function(){
        var self = this ;
        this.updateState();
        this.scheduleOnce(function(){
            self.node.active = false ;
        },0.1)
    },
    toggleClick:function(btn,index){
        if(index==1){
          this.musicState = btn.isChecked
        }
        if(index==2){
          this.soundState = btn.isChecked  
        }   
    },
});